#-------------------------------------------------------------------------------
# Name:       audio_converter_linux.py
# Purpose:    Convert text to audio files
#
# Authors:    Glenn Ramsey <glenn.ramsey@slidespeech.com>
#
# Copyright:  (c) Slidespeech Ltd 2012
# Licence:    MIT license
#-------------------------------------------------------------------------------

import os
import subprocess

class AudioConfig:
    ttsURL = "http://espeak.sourceforge.net/"
    ttsEngine = "espeak"
    ttsExe = "espeak"
    oggEncoder = "oggenc"
    mp3Encoder = "lame"

def encodeOgg(path, inFileName, outFileName):
    return subprocess.call(['oggenc', inFileName, '-o', outFileName])

def encodeMp3(path, inFileName, outFileName):
    return subprocess.call(['lame', '-V2', inFileName, outFileName])

def textToAudio(text, language, path, basename):
    filename = os.path.join(path, basename + '.wav')
    ret = subprocess.call(['espeak', '-v', language, '-w', filename, text])
    if ret:
        raise RuntimeError("Could not generate audio, {0} failed".format(AudioConfig.ttsEngine))

    return filename
    